package cn.cupster.motionlayoutshare.example

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.constraintlayout.motion.widget.MotionLayout
import cn.cupster.motionlayoutshare.R

/**
 * 跑马灯效果
 */
class MarqueeActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_marquee)
        anim = findViewById(R.id.motionLayout)
        anim?.addTransitionListener(object : MotionLayout.TransitionListener {
            override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) {

            }

            override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, p3: Float) {

            }

            override fun onTransitionCompleted(motionLayout: MotionLayout?, p1: Int) {
                //循环跑马灯
                motionLayout?.transitionToStart()
                motionLayout?.setTransition(R.id.transAnim)
                motionLayout?.setTransitionDuration(8000)
                motionLayout?.transitionToEnd()
            }

            override fun onTransitionTrigger(p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) {

            }
        })
    }

    var anim: MotionLayout? = null

    override fun onResume() {
        super.onResume()

        anim?.postDelayed({
            anim?.performClick()
        }, 300)
    }

    override fun onPause() {
        super.onPause()

    }

}